home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / bgui12.lha / demos / democode.h < prev    next >
C/C++ Source or Header  |  1995-07-15  |  2KB  |  120 lines

  1. /*
  2.  *    DEMOCODE.H
  3.  *
  4.  *    (C) Copyright 1995 Jaba Development.
  5.  *    (C) Copyright 1995 Jan van den Baard.
  6.  *        All Rights Reserved.
  7.  */
  8.  
  9. #include <exec/types.h>
  10. #include <exec/memory.h>
  11. #include <dos/dos.h>
  12. #include <libraries/gadtools.h>
  13. #include <libraries/bgui.h>
  14. #include <libraries/bgui_macros.h>
  15. #include <intuition/sghooks.h>
  16. #include <graphics/gfxmacros.h>
  17. #include <workbench/workbench.h>
  18. #include <workbench/startup.h>
  19.  
  20. #include <clib/alib_protos.h>
  21.  
  22. #include <proto/exec.h>
  23. #include <proto/intuition.h>
  24. #include <proto/dos.h>
  25. #include <proto/bgui.h>
  26. #include <proto/graphics.h>
  27. #include <proto/diskfont.h>
  28.  
  29. #include <stdlib.h>
  30.  
  31. #ifdef _DCC
  32. #define SAVEDS __geta4
  33. #define ASM
  34. #define REG(x) __ ## x
  35. #define CHIP(t) __chip t
  36. #else
  37. #define SAVEDS __saveds
  38. #define ASM __asm
  39. #define REG(x) register __ ## x
  40. #define CHIP(t) t chip
  41. #endif
  42.  
  43. /*
  44.  *    The entry point of all demo programs.
  45.  */
  46. extern VOID StartDemo( void );
  47.  
  48. /*
  49.  *    Output file handle and BGUI
  50.  *    library base.
  51.  */
  52. BPTR        StdOut;
  53. struct Library *BGUIBase;
  54.  
  55. /*
  56.  *    Output text to the CLI or Workbench console.
  57.  */
  58. VOID Tell( UBYTE *fstr, ... )
  59. {
  60.     if ( StdOut ) VFPrintf( StdOut, fstr, ( ULONG * )&fstr + 1 );
  61. }
  62.  
  63. /*
  64.  *    Main entry point.
  65.  */
  66. int main( int argc, char **argv )
  67. {
  68.     struct Process            *this_task = ( struct Process * )FindTask( NULL );
  69.     BOOL                 is_wb = FALSE;
  70.  
  71.     if ( this_task->pr_CLI )
  72.         /*
  73.          *    Started from the CLI. Simply pickup
  74.          *    the CLI output handle.
  75.          */
  76.         StdOut = Output();
  77.     else {
  78.         /*
  79.          *    Workbench startup. Open a console
  80.          *    for output.
  81.          */
  82.         StdOut = Open( "CON:10/10/500/100/BGUI Demo Output/WAIT/AUTO", MODE_NEWFILE );
  83.         is_wb = TRUE;
  84.     }
  85.  
  86.     /*
  87.      *    Open BGUI.
  88.      */
  89.     if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )) {
  90.         /*
  91.          *    Run the demo.
  92.          */
  93.         StartDemo();
  94.         CloseLibrary( BGUIBase );
  95.     } else
  96.         Tell( "Unable to open %s version %ld\n", BGUINAME, BGUIVERSION );
  97.  
  98.     /*
  99.      *    Close console if ran from
  100.      *    the workbench.
  101.      */
  102.     if ( is_wb ) {
  103.         if ( StdOut ) Close( StdOut );
  104.     }
  105.  
  106.     return( 0 );
  107. }
  108.  
  109. /*
  110.  *    DICE stub which simply calls
  111.  *    main() when run from the
  112.  *    workbench.
  113.  */
  114. #ifdef _DCC
  115. int wbmain( struct WBStartup *wbs )
  116. {
  117.     return( main( NULL, 0 ));
  118. }
  119. #endif
  120.